package com.itheima.infoManager.arraylistDemo.manager.service;

import com.itheima.infoManager.arraylistDemo.manager.dao.OtherTeacherDao;
import com.itheima.infoManager.arraylistDemo.manager.domain.Teacher;

public class TeacherService {
    private OtherTeacherDao dao = new OtherTeacherDao();
    //添加
    public boolean addTeacher(Teacher teacher) {
        //service层没有数据操作权限，所以将数据向下传递
        return dao.addTeacher(teacher);//将controller层的请求，向下提交，让dao层完成数据添加操作
    }

    //判断学号是否存在重复
    public boolean isExists(String id) {
        Teacher[] teachers = dao.findAllTeacher();
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            //判断数组中的Student对象的id属性是否有和当前id一样的
            if (teacher!=null && teacher.getId().equals(id)){
                return true;
            }
        }
        return false;
    }

    //查看
    public Teacher[] findAllTeacher() {
        //拿到数组
        Teacher[] allTeacher = dao.findAllTeacher();
        //遍历
        for (int i = 0; i < allTeacher.length; i++) {
            Teacher stu = allTeacher[i];
            //如果数组内有值，则将数组返回
            if (stu!=null){
                return allTeacher;
            }
        }
        //没有值则返回null，交给上一层去判断
        return null;
    }

    //删除
    public boolean deleteTeacher(String delId) {
        return dao.deleteTeacher(delId);
    }

    public boolean updateTeacher(String upId, Teacher teacher) {
        return dao.updateTeacher(upId,teacher);
    }
}
